import config from 'config';
import _ from 'lodash';

export const apis: { [name: string]: string } = config.get('apis');

export const sourceMap = {
    ..._.mapValues(
        apis,
        (value) => _.template(value)({gateway: config.get('gateway')}),
    ),
};

export default function(url: string) {
    const match = /^<(\w*)>\/(.*)$/.exec(url);
    if (match) {
        return `${apis[match[1]]}/${match[2]}`;
    }
    return url;
}
